﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Text.RegularExpressions;

public partial class Main_Inventory_DCInward : System.Web.UI.Page
{
    string TFOID = "";
    string Supplierid = "";
    string TRNID = "";
    string TITID = "";
    string TIDIDCollection = "";
    string FINYEAR = "";
    string strsql = "";
    Datautility DU = new Datautility();
    int dccounter = 2;
    List<string> listdccounter;
    List<string> listitem;
    List<string> listhidTITID;
    List<string> listhidTIDID;
    List<string> listuom;
    List<string> listhuomid;
    List<string> listqty;
    List<string> listbtnqty;
    List<string> listhidLocationBillLevel;
    List<string> listrate;
    List<string> listhidTaxRate;
    List<string> listamount;
    List<string> listhidtaxamt;
    protected override void LoadViewState(object savedState)
    {
        base.LoadViewState(savedState);
        overrideADDMORE();


    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["TFOID"] != null && Request.QueryString["trnid"] != null)
        {
            TFOID = Request.QueryString["TFOID"].ToString();
            TRNID = Request.QueryString["trnid"].ToString();
            hidTRNID.Value = Request.QueryString["trnid"].ToString();
            Supplierid = Request.QueryString["supplierid"].ToString();
            FINYEAR = Request.QueryString["finyear"].ToString();
        }
        if (!IsPostBack)
        {
            listdccounter = new List<string>();
            ViewState["listdccounter"] = listdccounter;

            listitem = new List<string>();
            ViewState["listitem"] = listitem; 

            listhidTITID = new List<string>();
            ViewState["listhidTITID"] = listhidTITID;

            listhidTIDID = new List<string>();
            ViewState["listhidTIDID"] = listhidTIDID;

            listuom = new List<string>();
            ViewState["listuom"] = listuom;

            listhuomid = new List<string>();
            ViewState["listhuomid"] = listhuomid;

            listqty = new List<string>();
            ViewState["listqty"] = listqty;

            listbtnqty = new List<string>();
            ViewState["listbtnqty"] = listbtnqty;

            listhidLocationBillLevel = new List<string>();
            ViewState["listhidLocationBillLevel"] = listhidLocationBillLevel;

            listrate = new List<string>();
            ViewState["listrate"] = listrate;

            listhidTaxRate = new List<string>();
            ViewState["listhidTaxRate"] = listhidTaxRate;

            listamount = new List<string>();
            ViewState["listamount"] = listamount;

            listhidtaxamt = new List<string>();
            ViewState["listhidtaxamt"] = listhidtaxamt;

            bindformate();
            bindsupplier();
            bindtaxgroup();
            bindcategor();
            binditem(ddlitems1);
            binditem(ddlitems2);

            EditHeadSection();
           

            if (Request.QueryString["msg"] != null)
            {
                if (Request.QueryString["msg"].ToString() == "true")
                {
                    lblMsg.Text = " Delivery Challan Updated ";
                    //grdview.Focus();
                }
            }
            else
            {
                lblMsg.Text = "";
            }
            //BindView();  gridview data
        }
        //overrideADDMORE();
        BindJavaScriptBillLevel();
        
    }
    protected void EditHeadSection()
    {
        ddldcformate.SelectedValue = TFOID;
        ddldcformate_SelectedIndexChanged(this, EventArgs.Empty);

        SqlParameter[] parma = { 
                                 new SqlParameter("@TRNID",TRNID)
                               };
        DataTable dtMain = DU.getdatausingprocedure("usp_ivr_get_DCIN_Edit_Main_by_trnid", parma);
        if (dtMain.Rows.Count > 0)
        {
            txtdate.Text = string.Format("{0:dd/MM/yyyy}", Convert.ToDateTime(dtMain.Rows[0]["TRNDATE"].ToString())).Replace("01/01/1900","") ;

            ddlsupplier.SelectedValue = Supplierid;
            ddlsupplier_SelectedIndexChanged(this, EventArgs.Empty);
            ddltaxgroup.SelectedValue = dtMain.Rows[0]["DCTAX_SUBCLASSID"].ToString();
        }
        EditBindAddMoreRow();
        EditBindDeliveryOthers();
    }
    protected void EditBindAddMoreRow()
    {
        SqlParameter[] parmaitems = {
                                     new SqlParameter("@TRNID",TRNID)
                                    };
        DataTable dtitems = DU.getdatausingprocedure("usp_get_DCIn_Edit_Items", parmaitems);
       // Response.Write(dtitems.Rows.Count.ToString());
        if (dtitems.Rows.Count > 0)
        {
            for (int i = 2; i < dtitems.Rows.Count; i++)
            {
                AddMoreRow();
                BindJavaScriptBillLevel();
            }
            EditBindItems(dtitems);

        }
    }
    protected void EditBindItems(DataTable dtitems)
    {
        if (dtitems.Rows.Count > 0)
        {
            for (int i = 1; i <= dtitems.Rows.Count; i++)
            {
                DropDownList ddlItemBillLevel = (DropDownList)tblitem.Rows[i].FindControl("ddlitems" + i.ToString());
                HiddenField hidTITID = (HiddenField)tblitem.Rows[i].FindControl("hidTITID" + i.ToString());
                HiddenField hidUnitIdBillLevel = (HiddenField)tblitem.Rows[i].FindControl("huomid" + i.ToString());
                TextBox txtQuantityBillLevel = (TextBox)tblitem.Rows[i].FindControl("txtquantity" + i.ToString());
                TextBox txtRateBillLevel = (TextBox)tblitem.Rows[i].FindControl("txtrate" + i.ToString());
                TextBox txtAmountBillLevel = (TextBox)tblitem.Rows[i].FindControl("txtamount" + i.ToString());
                HiddenField hidLocationBillLevel = (HiddenField)tblitem.Rows[i].FindControl("hidLocationBillLevel" + i.ToString());
                HiddenField hidTIDID = (HiddenField)tblitem.Rows[i].FindControl("hidTIDID" + i.ToString());

                ddlItemBillLevel.SelectedValue = dtitems.Rows[i-1]["ITMID"].ToString();
                ddlitems_OnSelectedIndexChanged(ddlItemBillLevel, EventArgs.Empty);
                hidUnitIdBillLevel.Value = dtitems.Rows[i-1]["UOMID"].ToString();
                txtQuantityBillLevel.Text = dtitems.Rows[i-1]["ITMQTY"].ToString();
                txtRateBillLevel.Text = dtitems.Rows[i-1]["RATE"].ToString();
                txtAmountBillLevel.Text = dtitems.Rows[i-1]["ITMAMT"].ToString();
                hidLocationBillLevel.Value = EditBindLocation(dtitems.Rows[i - 1]["ITMID"].ToString(), dtitems.Rows[i - 1]["TITID"].ToString());

                hidTITID.Value = dtitems.Rows[i - 1]["TITID"].ToString();
                //hidTITID.Value = dtitems.Rows[i - 1]["TITID"].ToString();
                hidTIDID.Value = EditDetailedLocation(hidTITID.Value);
                //Response.Write("Tiddid=" + hidTIDID.Value);
                //Response.Write("Tit=" + hidTITID.Value);
                //hidTIDIDCollection.Value = EditDetailedLocation(TITID);
            }
        }
    }
    protected string EditBindLocation(string ITMID, string TITID)
    {
        string LocationIdandQty = string.Empty;
        if (ITMID != string.Empty && TITID != string.Empty)
        {
            SqlParameter[] parma = {
                                    new SqlParameter("@TITID",TITID)
                                   };
            DataTable dtDetaillocation = DU.getdatausingprocedure("usp_get_DCIn_Edit_ItemsDetails", parma);
            if (dtDetaillocation.Rows.Count > 0)
            {
                for (int i = 0; i < dtDetaillocation.Rows.Count; i++)
                {
                    if (isBatchEnabled(ITMID) && isWarrantyEnabled(ITMID))
                    {
                        if (i == 0)
                        {
                            LocationIdandQty += dtDetaillocation.Rows[i]["whsid"].ToString() + ',' +string.Format("{0:0.00}", dtDetaillocation.Rows[i]["DETQTY"].ToString()) + '|' + dtDetaillocation.Rows[i]["BATID"].ToString() + ':' + dtDetaillocation.Rows[i]["WARRANTY"].ToString() + ';' + dtDetaillocation.Rows[i]["WARRANTYPERIOD"].ToString();
                        }
                        else if(i>0)
                        {
                            LocationIdandQty += "/"+ dtDetaillocation.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtDetaillocation.Rows[i]["DETQTY"].ToString()) + '|' + dtDetaillocation.Rows[i]["BATID"].ToString() + ':' + dtDetaillocation.Rows[i]["WARRANTY"].ToString() + ';' + dtDetaillocation.Rows[i]["WARRANTYPERIOD"].ToString();
                        }
                    }
                    else if (isBatchEnabled(ITMID) && !isWarrantyEnabled(ITMID))
                    {
                        if (i == 0)
                        {
                            LocationIdandQty += dtDetaillocation.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtDetaillocation.Rows[i]["DETQTY"].ToString()) + '|' + dtDetaillocation.Rows[i]["BATID"].ToString();
                        }
                        else if (i > 0)
                        {
                            LocationIdandQty += "/" + dtDetaillocation.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtDetaillocation.Rows[i]["DETQTY"].ToString()) + '|' + dtDetaillocation.Rows[i]["BATID"].ToString();
                        }
                    }
                    else if (!isBatchEnabled(ITMID) && !isWarrantyEnabled(ITMID))
                    {
                        if (i == 0)
                        {
                            LocationIdandQty += dtDetaillocation.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtDetaillocation.Rows[i]["DETQTY"].ToString());
                        }
                        else if (i > 0)
                        {
                            LocationIdandQty += "/" + dtDetaillocation.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtDetaillocation.Rows[i]["DETQTY"].ToString());
                        }
                    }
                }
            }
        }
        return LocationIdandQty;
    }
    protected string EditDetailedLocation(string TITID)
    {
        string Detailid = string.Empty;
        if (TITID != string.Empty)
        {
            SqlParameter[] parma = {
                                    new SqlParameter("@TITID",TITID)
                                   };
            DataTable dtDetaillocation = DU.getdatausingprocedure("usp_get_DCIn_Edit_ItemsDetails", parma);
            if (dtDetaillocation.Rows.Count > 0)
            {
                for (int i = 0; i < dtDetaillocation.Rows.Count; i++)
                {
                    if (i == 0)
                    {
                        Detailid += dtDetaillocation.Rows[i]["TIDID"].ToString();
                    }
                    else if (i > 0)
                    {
                        Detailid += "/" + dtDetaillocation.Rows[i]["TIDID"].ToString();
                    }
                }
            }
        }
        return Detailid;
    }
    protected void EditBindDeliveryOthers()
    {
        SqlParameter[] parmaothers = { 
                                      new SqlParameter("@TRNID",TRNID)
                                     };
            DataTable dtDeliveryother= DU.getdatausingprocedure("usp_ivr_get_delivery_others", parmaothers);
            if (dtDeliveryother.Rows.Count > 0)
            {
                txtmodeofdelivery.Text = dtDeliveryother.Rows[0]["MODEOFDELIVERY"].ToString();
                txtfreightindicator.Text = dtDeliveryother.Rows[0]["FREIGHTINDICATOR"].ToString();
                txttransportername.Text = dtDeliveryother.Rows[0]["TRANSPORTNAME"].ToString();
                txtdocumentno.Text = dtDeliveryother.Rows[0]["DOCUMENTNUM"].ToString();
                txtdeliverydate.Text = string.Format("{0:dd/MM/yyyy}", Convert.ToDateTime(dtDeliveryother.Rows[0]["DELIVERYDATE"].ToString())).Replace("01/01/1900","");
                txtvehicleno.Text = dtDeliveryother.Rows[0]["VEHICLENUM"].ToString();
                txtpreparedby.Text = dtDeliveryother.Rows[0]["PREPAREDBY"].ToString();
                txtcheckedby.Text = dtDeliveryother.Rows[0]["CHECKEDBY"].ToString();
                txtauthorisedsignature.Text = dtDeliveryother.Rows[0]["AUTHRSDSIGNAT"].ToString();
                txtnote.Text = dtDeliveryother.Rows[0]["NOTE"].ToString();
                txtremarks.Text = dtDeliveryother.Rows[0]["REMARKS"].ToString();
            }
      
    }
    //protected void BindView()
    //{
    //    DataTable dtgrdview = DU.getdatausingprocedure("usp_ivr_displayDCInward");
    //    if (dtgrdview.Rows.Count > 0)
    //    {
    //        grdview.DataSource = dtgrdview;
    //        grdview.DataBind();
    //    }
    //}
    protected void bindformate()
    {
        DataTable dtformatname = DU.getdatausingprocedure("usp_ivr_get_tranformatename");
        ddldcformate.DataSource = dtformatname;
        ddldcformate.DataTextField = "formatname";
        ddldcformate.DataValueField = "tfoid";
        ddldcformate.DataBind();
        ListItem li = new ListItem("----- Select Format -----", "0");
        ddldcformate.Items.Insert(0, li);
        li.Selected = true;

        ddldcformate.Enabled = false;
    }
    protected void ddldcformate_SelectedIndexChanged(object sender, EventArgs e)
    {
        lblMsg.Text = "";
        int finyear = 0;
        if (Session["FINYEAR"] != null)
        {
            finyear = Convert.ToInt32(FINYEAR); // Come from inward for edit
        }
        else
        {
            Response.Redirect("~/SessionExpired.aspx");
        }
        SqlParameter[] parma = {
                                  new SqlParameter("@TRNID",TRNID)
                                 };
        DataTable dtdcformatno = DU.getdatausingprocedure("usp_ivr_Get_DCNO_by_TRNID", parma);
        if (dtdcformatno.Rows.Count > 0)
        {
            txtPrefix.Enabled = false;
            txtVoucher.Enabled = false;
            txtSuffix.Enabled = false;

            txtPrefix.Text = dtdcformatno.Rows[0]["NUMPREFIX"].ToString();
            txtVoucher.Text = dtdcformatno.Rows[0]["trnnum"].ToString();
            txtSuffix.Text = dtdcformatno.Rows[0]["NUMSUFFIX"].ToString();
        }
        CheckTranFormate();
    }
    protected void bindsupplier()
    {
        DataTable dtsupplier = DU.getdatausingprocedure("USP_ACC_GetLedgerForPurchaseInvoice");
        if (dtsupplier.Rows.Count > 0)
        {
            ddlsupplier.DataSource = dtsupplier;
            ddlsupplier.DataTextField = "LNAME";
            ddlsupplier.DataValueField = "LID";
            ddlsupplier.DataBind();
            ListItem li = new ListItem("-- Select Supplier --", "0");
            ddlsupplier.Items.Insert(0, li);
            li.Selected = true;

        }
    }
    protected void bindDeliveryAdd()
    {
        SqlParameter[] parrr = { 
                                 new SqlParameter("@ledid",ddlsupplier.SelectedValue)
                               };
        DataTable dtdeladd = DU.getdatausingprocedure("usp_get_deliveryadd_by_ledid", parrr);
        if (dtdeladd.Rows.Count > 0)
        {
            hiddelivery_id.Value = dtdeladd.Rows[0]["deliveryaddid"].ToString();
            StringBuilder sb = new StringBuilder();
            sb.Append(dtdeladd.Rows[0]["Title"].ToString()+" , ");
            sb.Append(dtdeladd.Rows[0]["contactname"].ToString() + "\n");
            sb.Append(dtdeladd.Rows[0]["add1"].ToString() + " ");
            sb.Append(dtdeladd.Rows[0]["add2"].ToString() + " ");
            sb.Append(dtdeladd.Rows[0]["add3"].ToString() + " ");
            sb.Append(dtdeladd.Rows[0]["pincode"].ToString() + "\n  ");
            sb.Append(dtdeladd.Rows[0]["state"].ToString() + "\n  ");
            sb.Append(dtdeladd.Rows[0]["country"].ToString() + " ");

            txtdeliveryadd.Text = sb.ToString();
        }
    }
    protected void ddlsupplier_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindDeliveryAdd();
    }
    protected void bindtaxgroup()
    {
        SqlParameter[] parma = { 
                                new SqlParameter("@ISDCIN","1")
                               };
    
        DataTable dttaxgroup = DU.getdatausingprocedure("USP_IVR_GetDCGroup", parma);
        if (dttaxgroup.Rows.Count > 0)
        {
            ddltaxgroup.DataSource = dttaxgroup;
            ddltaxgroup.DataTextField = "subclass";
            ddltaxgroup.DataValueField = "id";
            ddltaxgroup.DataBind();
            ListItem li = new ListItem("--- Select Tax Group ---","0");
            ddltaxgroup.Items.Insert(0, li);
            li.Selected = true;
            
        }
    }
    protected void bindcategor()
    {
        ListItem li = new ListItem("--- Select Categor ---", "0");
        ddlcategory.Items.Insert(0, li);
        li.Selected = true;
    }

    protected void binditem( DropDownList ddl)
    {
        DataTable dtitem = DU.getdatausingprocedure("usp_ivr_get_all_item");
        if (dtitem.Rows.Count > 0)
        {
            ddl.DataSource = dtitem;
            ddl.DataTextField = "ITMDESC";
            ddl.DataValueField = "ITMID";
            ddl.DataBind();
            ddl.Items.Insert(0, new ListItem("--- Select Items ---", "0"));

        }
    }
    //protected void binduom(string itemid, int rowno)
    //{
    //    if (itemid.ToString() != string.Empty)
    //    {
    //        SqlParameter[] parr = { 
    //                          new SqlParameter("@itemid",itemid)
    //                          };
    //        DataTable dtuom = DU.getdatausingprocedure("usp_ivr_get_uom_by_itemid", parr);
    //        if (dtuom.Rows.Count > 0)
    //        {
    //            TextBox txtunit = (TextBox)tblitem.Rows[rowno].FindControl("txtunit" + rowno.ToString());
    //            HiddenField huono = (HiddenField)tblitem.Rows[rowno].FindControl("huomid" + rowno.ToString());
    //            txtunit.Text = dtuom.Rows[0]["UOMNAME"].ToString();
    //            huono.Value = dtuom.Rows[0]["UOMID"].ToString();

    //        }
    //    }
    //}
    protected void ddlitems_OnSelectedIndexChanged(object sender,EventArgs e)
    {
        DropDownList ddl = (DropDownList)sender;
        string ddlid = ddl.ID.ToString().Substring(8);
        int rowno = Convert.ToInt32(ddlid.ToString());
        TextBox txtunit = (TextBox)tblitem.Rows[rowno].FindControl("txtunit" + rowno.ToString());
        HiddenField huono = (HiddenField)tblitem.Rows[rowno].FindControl("huomid" + rowno.ToString());
        TextBox txtQuantity = (TextBox)tblitem.Rows[rowno].FindControl("txtquantity" + rowno.ToString());
        TextBox txtRate = (TextBox)tblitem.Rows[rowno].FindControl("txtrate" + rowno.ToString());
        TextBox txtAmount = (TextBox)tblitem.Rows[rowno].FindControl("txtamount" + rowno.ToString());

        txtunit.Text = string.Empty;
        huono.Value = string.Empty;
        txtQuantity.Text = string.Empty;
        txtRate.Text = string.Empty;
        txtAmount.Text = string.Empty;

        SqlParameter[] parr = { 
                              new SqlParameter("@itemid",ddl.SelectedValue)
                              };
        DataTable dtuom = DU.getdatausingprocedure("usp_ivr_get_uom_by_itemid", parr);
        if (dtuom.Rows.Count > 0)
        {
                if (ddlsupplier.SelectedValue != "0")
                {
                   
                        lblMsg.Text = "";
                        txtunit.Text = dtuom.Rows[0]["UOMNAME"].ToString();
                        huono.Value = dtuom.Rows[0]["UOMID"].ToString();
                   
                        
                    
                }
                else
                {
                    ddl.SelectedIndex = 0;
                    lblMsg.ForeColor = System.Drawing.Color.Red;
                    lblMsg.Text = "Please Select Supplier";
                    ddlsupplier.Focus();
                    txtunit.Text = string.Empty;
                    huono.Value = string.Empty;
                }
                if (ddl.SelectedValue == "0")
                {
                    txtunit.Text = string.Empty;
                    huono.Value = string.Empty;
                    txtQuantity.Text = string.Empty;
                    txtRate.Text = string.Empty;
                    txtAmount.Text = string.Empty;
                }
        }
        
        BindJavaScriptBillLevel();
        
    }
    protected void AddMoreRow()
    {
        dccounter++;
        listdccounter.Add(dccounter.ToString());

        HtmlTableRow row1 = new HtmlTableRow();
        HtmlTableCell cell1 = new HtmlTableCell();
        cell1.Align = "Center";
        DropDownList ddl = new DropDownList();
        ddl.ID = "ddlitems" + dccounter.ToString();
        ddl.CssClass = "dropdown";
        ddl.Width = Unit.Percentage(95);
        binditem(ddl);
        ddl.Attributes.Add("onchange", "return checkItemRepetion(this.id);");
        ddl.AutoPostBack = true;
        ddl.SelectedIndexChanged += new EventHandler(ddlitems_OnSelectedIndexChanged);
        
        listitem.Add(ddl.ID);

        HiddenField hidTITID = new HiddenField();
        hidTITID.ID = "hidTITID" + dccounter.ToString();

        listhidTITID.Add(hidTITID.ID);

        HiddenField hidTIDID = new HiddenField();
        hidTIDID.ID = "hidTIDID" + dccounter.ToString();

        listhidTIDID.Add(hidTIDID.ID);

        HtmlTableCell cell2 = new HtmlTableCell();
        cell2.Align = "Center";
        TextBox txtunit = new TextBox();
        txtunit.ID = "txtunit" + dccounter.ToString();
        txtunit.Width = Unit.Percentage(95);
        txtunit.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
        txtunit.CssClass = "input";
        listuom.Add(txtunit.ID);

        HiddenField huomid = new HiddenField();
        huomid.ID = "huomid" + dccounter.ToString();
        listhuomid.Add(huomid.ID);

        HtmlTableCell cell3 = new HtmlTableCell();
        cell3.Align = "Center";
        TextBox txtquantity = new TextBox();
        txtquantity.ID = "txtquantity" + dccounter.ToString();
        txtquantity.Width = Unit.Percentage(88);
        txtquantity.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
        txtquantity.CssClass = "inputnumber";
        listqty.Add(txtquantity.ID);

        Label lblspace = new Label();
        lblspace.Text = "&nbsp;";

        Button btnQtyBillLevel = new Button();
        btnQtyBillLevel.ID = "btnQtyBillLevel" + dccounter.ToString();
        btnQtyBillLevel.CssClass = "button";
        btnQtyBillLevel.Width = Unit.Percentage(5);
        btnQtyBillLevel.Text = "...";
        
        listbtnqty.Add(btnQtyBillLevel.ID);

        HiddenField hidLocationBillLevel = new HiddenField();
        hidLocationBillLevel.ID = "hidLocationBillLevel" + dccounter.ToString();
        listhidLocationBillLevel.Add(hidLocationBillLevel.ID);

        HtmlTableCell cell4 = new HtmlTableCell();
        cell4.Align = "Center";
        TextBox txtrate = new TextBox();
        txtrate.ID = "txtrate" + dccounter.ToString();
        txtrate.Width = Unit.Percentage(95);
        txtrate.Attributes.Add("OnKeyPress", "return isNumberKey(this.ID,event);");
        txtrate.Attributes.Add("onBlur", "return CalculateAmtBillLevel();");
        txtrate.CssClass = "inputnumber";
        listrate.Add(txtrate.ID);

        HiddenField hidTaxRate = new HiddenField();
        hidTaxRate.ID = "hidTaxRate" + dccounter.ToString();
        listhidTaxRate.Add(hidTaxRate.ID);

        HtmlTableCell cell5 = new HtmlTableCell();
        cell5.Align = "Center";
        TextBox txtamount = new TextBox();
        txtamount.ID = "txtamount" + dccounter.ToString();
        txtamount.Width = Unit.Percentage(95);
        txtamount.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
        txtamount.CssClass = "inputnumber";
        listamount.Add(txtamount.ID);

        HiddenField hidtaxamt = new HiddenField();
        hidtaxamt.ID = "hidtaxamt" + dccounter.ToString();
        listhidtaxamt.Add(hidtaxamt.ID);

        cell1.Controls.Add(ddl);
        cell1.Controls.Add(hidTITID);
        cell1.Controls.Add(hidTIDID);
        cell2.Controls.Add(txtunit);
        cell2.Controls.Add(huomid);
        cell3.Controls.Add(txtquantity);
        cell3.Controls.Add(lblspace);
        cell3.Controls.Add(btnQtyBillLevel);
        cell3.Controls.Add(hidLocationBillLevel);
        cell4.Controls.Add(txtrate);
        cell4.Controls.Add(hidTaxRate);
        cell5.Controls.Add(txtamount);
        cell5.Controls.Add(hidtaxamt);

        row1.Cells.Add(cell1);
        row1.Cells.Add(cell2);
        row1.Cells.Add(cell3);
        row1.Cells.Add(cell4);
        row1.Cells.Add(cell5);

        tblitem.Rows.Add(row1);
        hcount.Value = dccounter.ToString();
       

        ViewState["listdccounter"] = listdccounter;
        ViewState["listitem"] = listitem;
        ViewState["listhidTITID"] = listhidTITID;
        ViewState["listhidTIDID"] = listhidTIDID;
        ViewState["listuom"] = listuom;        
        ViewState["listqty"] = listqty;        
        ViewState["listhuomid"] = listhuomid;        
        ViewState["listbtnqty"] = listbtnqty;
        ViewState["listhidLocationBillLevel"] = listhidLocationBillLevel;
        ViewState["listrate"] = listrate;
        ViewState["listhidTaxRate"] = listhidTaxRate;
        ViewState["listamount"] = listamount;
        ViewState["listhidtaxamt"] = listhidtaxamt;

    }
    protected void btnAddMore_Click(object sender, EventArgs e)
    {
        AddMoreRow();
        BindJavaScriptBillLevel();
    }
    protected void overrideADDMORE()
    {
        listdccounter = (List<string>)ViewState["listdccounter"];
        listitem = (List<string>)ViewState["listitem"];
        listhidTITID=(List<string>)ViewState["listhidTITID"];
        listhidTIDID = (List<string>)ViewState["listhidTIDID"];
        listuom = (List<string>)ViewState["listuom"];
        listhuomid = (List<string>)ViewState["listhuomid"];
        listqty = (List<string>)ViewState["listqty"];
        listbtnqty = (List<string>)ViewState["listbtnqty"];
        listhidLocationBillLevel = (List<string>)ViewState["listhidLocationBillLevel"];
        listrate = (List<string>)ViewState["listrate"];
        listhidTaxRate = (List<string>)ViewState["listhidTaxRate"];
        listamount = (List<string>)ViewState["listamount"];
        listhidtaxamt = (List<string>)ViewState["listhidtaxamt"];

        if (listdccounter != null)
        {
            int temdccounter = Convert.ToInt32(listdccounter.Count);
            for (int i = 0; i < temdccounter; i++)
            {
                dccounter++;
                
                HtmlTableRow row1 = new HtmlTableRow();

                HtmlTableCell cell1 = new HtmlTableCell();
                cell1.Align = "Center";
                DropDownList ddl = new DropDownList();
                ddl.ID =  listitem[i].ToString();
                ddl.CssClass = "dropdown";
                ddl.Width = Unit.Percentage(95);
                binditem(ddl);
                ddl.Attributes.Add("onchange", "return checkItemRepetion(this.id);");
                ddl.AutoPostBack = true;
                ddl.SelectedIndexChanged += new EventHandler(ddlitems_OnSelectedIndexChanged);

                HiddenField hidTITID = new HiddenField();
                hidTITID.ID = listhidTITID[i].ToString();

                HiddenField hidTIDID = new HiddenField();
                hidTIDID.ID = listhidTIDID[i].ToString();

                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.Align = "Center";
                TextBox txtunit = new TextBox();
                txtunit.ID =  listuom[i].ToString();
                txtunit.Width = Unit.Percentage(95);
                txtunit.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
                txtunit.CssClass = "input";

                HiddenField huomid = new HiddenField();
                huomid.ID =  listhuomid[i].ToString();

                HtmlTableCell cell3 = new HtmlTableCell();
                cell3.Align = "Center";
                TextBox txtquantity = new TextBox();
                txtquantity.ID =  listqty[i].ToString();
                txtquantity.Width = Unit.Percentage(88);
                txtquantity.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
                txtquantity.CssClass = "inputnumber";

                Label lblspace = new Label();
                lblspace.Text = "&nbsp;";

                Button btnQtyBillLevel = new Button();
                btnQtyBillLevel.ID = listbtnqty[i].ToString();
                btnQtyBillLevel.CssClass = "button";
                btnQtyBillLevel.Width = Unit.Percentage(5);
                btnQtyBillLevel.Text = "...";

                HiddenField hidLocationBillLevel = new HiddenField();
                hidLocationBillLevel.ID = listhidLocationBillLevel[i].ToString();

                HtmlTableCell cell4 = new HtmlTableCell();
                cell4.Align = "Center";
                TextBox txtrate = new TextBox();
                txtrate.ID = listrate[i].ToString();
                txtrate.Width = Unit.Percentage(95);
                txtrate.Attributes.Add("OnKeyPress", "return isNumberKey(this.ID,event);");
                txtrate.Attributes.Add("onBlur", "return CalculateAmtBillLevel();");
                txtrate.CssClass = "inputnumber";

                HiddenField hidTaxRate = new HiddenField();
                hidTaxRate.ID = listhidTaxRate[i].ToString();

                HtmlTableCell cell5 = new HtmlTableCell();
                cell5.Align = "Center";
                TextBox txtamount = new TextBox();
                txtamount.ID =  listamount[i].ToString();
                txtamount.Width = Unit.Percentage(95);
                txtamount.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
                txtamount.CssClass = "inputnumber";

                HiddenField hidtaxamt = new HiddenField();
                hidtaxamt.ID = listhidtaxamt[i].ToString();

                cell1.Controls.Add(ddl);
                cell1.Controls.Add(hidTITID);
                cell1.Controls.Add(hidTIDID);
                cell2.Controls.Add(txtunit);
                cell2.Controls.Add(huomid);
                cell3.Controls.Add(txtquantity);
                cell3.Controls.Add(lblspace);
                cell3.Controls.Add(btnQtyBillLevel);
                cell3.Controls.Add(hidLocationBillLevel);
                cell4.Controls.Add(txtrate);
                cell4.Controls.Add(hidTaxRate);
                cell5.Controls.Add(txtamount);
                cell5.Controls.Add(hidtaxamt);

                row1.Cells.Add(cell1);
                row1.Cells.Add(cell2);
                row1.Cells.Add(cell3);
                row1.Cells.Add(cell4);
                row1.Cells.Add(cell5);

                tblitem.Rows.Add(row1);
            }
        }
    }
    protected void BindJavaScriptBillLevel()//A common function for add javascript attribute to btn quantity
    {
        int intCount = Convert.ToInt32(hcount.Value);
        for (int i = 1; i <= intCount; i++)
        {
            
            DropDownList ddlitems = (DropDownList)tblitem.Rows[i].FindControl("ddlitems" + i.ToString());
            TextBox txtquantity = (TextBox)tblitem.Rows[i].FindControl("txtquantity" + i.ToString());
            HiddenField hidLocationBillLevel = (HiddenField)tblitem.Rows[i].FindControl("hidLocationBillLevel" + i.ToString());
            Button btnQtyBillLevel = (Button)tblitem.Rows[i].FindControl("btnQtyBillLevel" + i.ToString());
            btnQtyBillLevel.Attributes.Add("onclick", "return GetQuantity('" + ddlitems.ClientID.ToString() + "', '" + txtquantity.ClientID.ToString() + "', '" + hidLocationBillLevel.ClientID.ToString() + "');");
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        SaveAll();
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("DCInward.aspx");
    }
    protected void SaveAll()
    {
        InsertItemTranMainBillLevel();
    }
    protected void CheckTranFormate()
    {
        if (ddldcformate.SelectedValue != "0")
        {
            SqlParameter[] parrr = { new SqlParameter("@TFOID", ddldcformate.SelectedValue) };
            DataTable dtpermission = DU.getdatausingprocedure("CheckTranFormat", parrr);
            if (dtpermission.Rows.Count > 0)
            {
                if (dtpermission.Rows[0]["DELIVERYDETAILS"].ToString() == "False")
                {
                    //divdeliverydetails.Disabled = true;
                    txtmodeofdelivery.Enabled = false;
                    txtfreightindicator.Enabled = false;
                    txttransportername.Enabled = false;
                    txtdocumentno.Enabled = false;
                    txtdeliverydate.Enabled = false;
                    txtvehicleno.Enabled = false;
                    btnimage.Enabled = false;
                    CalendarExtender1.Enabled = false;
                    spanRequireDate.Visible = false;
                    hidCheckDelivery.Value = "False";
                }
                else
                {
                    //divdeliverydetails.Disabled = false;
                    txtmodeofdelivery.Enabled = true;
                    txtfreightindicator.Enabled = true;
                    txttransportername.Enabled = true;
                    txtdocumentno.Enabled = true;
                    txtdeliverydate.Enabled = true;
                    txtvehicleno.Enabled = true;
                    btnimage.Enabled = true;
                    CalendarExtender1.Enabled = true;
                    spanRequireDate.Visible = true;
                    hidCheckDelivery.Value = "True";
                }

                if (dtpermission.Rows[0]["PREPAREDBY"].ToString() == "True")
                {
                    txtpreparedby.Enabled = true;
                }
                else
                {
                    txtpreparedby.Enabled = false;
                }
                if (dtpermission.Rows[0]["CHECKEDBY"].ToString() == "True")
                {
                    txtcheckedby.Enabled = true;
                }
                else
                {
                    txtcheckedby.Enabled = false;
                }
                if (dtpermission.Rows[0]["AUTHSIGNATORY"].ToString() == "True")
                {
                    txtauthorisedsignature.Enabled = true;
                }
                else
                {
                    txtauthorisedsignature.Enabled = false;
                }
                if (dtpermission.Rows[0]["NOTE"].ToString() == "True")
                {
                    txtnote.Enabled = true;
                }
                else
                {
                    txtnote.Enabled = false;
                }
                if (dtpermission.Rows[0]["REMARKS"].ToString() == "True")
                {
                    txtremarks.Enabled = true;
                }
                else
                {
                    txtremarks.Enabled = false;
                }
            }
        }
    }
    protected void InsertItemTranMainBillLevel()
    {
            string strFinYear = string.Empty;
            string strTransDate = string.Empty;
            string strEffectiveDate = string.Format("{0:MM/dd/yyyy}", System.DateTime.Now).ToString();
            strsql = "Select * from MAS_FINYEAR";
            DataTable DTFinYear = DU.getdata(strsql);
            if (DTFinYear.Rows.Count > 0)
            {
                strFinYear = DTFinYear.Rows[0]["FINYEAR"].ToString();
            }
            if (txtdate.Text.ToString() != string.Empty)
            {
                string[] str = txtdate.Text.ToString().Split('/');
                strTransDate = str[1].ToString() + "/" + str[0].ToString() + "/" + str[2].ToString();
            }
           
           
                SqlParameter[] sparam ={
                                       new SqlParameter("@TRNID",hidTRNID.Value),   /// Trnid for Update
                                       new SqlParameter("@TRANTYPEID","5"),
                                       new SqlParameter("@FINYEAR",strFinYear.ToString()),
                                       //new SqlParameter("@POID",Request.QueryString["Poid"].ToString()),
                                       //new SqlParameter("@INVOICENO",txtInvoiceNo.Text.Trim()),
                                       new SqlParameter("@TFOID",ddldcformate.SelectedValue),
                                       new SqlParameter("@TRNNUM",txtVoucher.Text.Trim()),
                                       new SqlParameter("@TRNDATE",strTransDate.ToString()),
                                       new SqlParameter("@VENDCUST_LID",ddlsupplier.SelectedValue),
                                       new SqlParameter("@TAX_MAINCLASSID","0"),
                                       new SqlParameter("@TRNSTATUS","1"),
                                       new SqlParameter("@MODEOFPAY","0"),
                                       new SqlParameter("@CREDITPERIOD","0"),
                                       new SqlParameter("@SURCHARGE","0"),  
                                       new SqlParameter("@DCTAX_SUBCLASSID",ddltaxgroup.SelectedValue),
                                       new SqlParameter("@ENAME",Session["username"].ToString())                                   
                               };
                int intResult = DU.executeprocedure("USP_IVR_UpdateTranMain", sparam);
                if (intResult > 0)
                {
                    //strsql = "Select Ident_Current('IVR_TRAN_MAIN') as TranId";
                    //DataTable DTTranid = DU.getdata(strsql);
                    //if (DTTranid.Rows.Count > 0)
                    //{
                    //    InsertItemTranItemBillLevel(DTTranid.Rows[0]["TranId"].ToString());
                    //    InsertTranDelivery(DTTranid.Rows[0]["TranId"].ToString());
                    //    InsertTranOthers(DTTranid.Rows[0]["TranId"].ToString());
                    //    Response.Redirect("DCInward.aspx?msg=true");
                    //}
                   
                        InsertItemTranItemBillLevel(hidTRNID.Value);
                        InsertTranDelivery(hidTRNID.Value);
                        InsertTranOthers(hidTRNID.Value);
                        Response.Redirect("DCInward.aspx?msg=update");
                        
                    
                    
                }
        
    }
    protected void InsertItemTranItemBillLevel(string strTranId)
    {
        if (strTranId.ToString() != string.Empty)
        {
            int intResult = 0;
            int intCount = Convert.ToInt32(hcount.Value);

            for (int i = 1; i <= intCount; i++)
            {

                DropDownList ddlItemBillLevel = (DropDownList)tblitem.Rows[i].FindControl("ddlitems" + i.ToString());
                HiddenField hidTITID = (HiddenField)tblitem.Rows[i].FindControl("hidTITID" + i.ToString());
                HiddenField hidUnitIdBillLevel = (HiddenField)tblitem.Rows[i].FindControl("huomid" + i.ToString());
                TextBox txtQuantityBillLevel = (TextBox)tblitem.Rows[i].FindControl("txtquantity" + i.ToString());
                TextBox txtRateBillLevel = (TextBox)tblitem.Rows[i].FindControl("txtrate" + i.ToString());
                TextBox txtAmountBillLevel = (TextBox)tblitem.Rows[i].FindControl("txtamount" + i.ToString());
                HiddenField hidTIDID = (HiddenField)tblitem.Rows[i].FindControl("hidTIDID" + i.ToString());
                if (txtQuantityBillLevel.Text != string.Empty && txtRateBillLevel.Text != string.Empty)
                {
                    double dblItemAmount = 0;
                    dblItemAmount = Convert.ToDouble(txtAmountBillLevel.Text) ;
                    if (hidTITID.Value != string.Empty)
                    {
                            SqlParameter[] sparam ={
                                   new SqlParameter("@TITID",hidTITID.Value),
                                   new SqlParameter("@TRNID",strTranId.ToString()),
                                   new SqlParameter("@ITMID",ddlItemBillLevel.SelectedValue ),
                                   new SqlParameter("@ITMQTY",txtQuantityBillLevel.Text.Trim()),
                                   new SqlParameter("@UOMID",hidUnitIdBillLevel.Value.ToString()),
                                   new SqlParameter("@RATE",txtRateBillLevel.Text.Trim()),
                                   new SqlParameter("@GROSSAMT",txtAmountBillLevel.Text.Trim()),
                                   new SqlParameter("@NETAMT",dblItemAmount),
                                   new SqlParameter("@TAX_TXMASID","0"),
                                   new SqlParameter("@TAXPER","0"),
                                   new SqlParameter("@TAXAMT","0"),
                                   new SqlParameter("@ITMAMT",dblItemAmount),
                                   new SqlParameter("@ITMPENDINGQTY",txtQuantityBillLevel.Text.Trim()),                               
                               };
                               intResult = DU.executeprocedure("USP_IVR_UpdateTranItem", sparam);
                    }
                    else
                    {
                        SqlParameter[] sparam ={
                                   new SqlParameter("@TRNID",strTranId.ToString()),
                                   new SqlParameter("@ITMID",ddlItemBillLevel.SelectedValue ),
                                   new SqlParameter("@ITMQTY",txtQuantityBillLevel.Text.Trim()),
                                   new SqlParameter("@UOMID",hidUnitIdBillLevel.Value.ToString()),
                                   new SqlParameter("@RATE",txtRateBillLevel.Text.Trim()),
                                   new SqlParameter("@GROSSAMT",txtAmountBillLevel.Text.Trim()),
                                   new SqlParameter("@NETAMT",dblItemAmount),
                                   new SqlParameter ("@TAX_TXMASID","0"),
                                   new SqlParameter("@TAXPER","0"),
                                   new SqlParameter("@TAXAMT","0"),
                                   new SqlParameter("@ITMAMT",dblItemAmount),
                                   new SqlParameter("@ITMPENDINGQTY",txtQuantityBillLevel.Text.Trim()),                               
                               };
                        intResult = DU.executeprocedure("USP_IVR_SaveTranItem", sparam);
                    }

                }
                if (txtQuantityBillLevel.Text == string.Empty && txtRateBillLevel.Text == string.Empty && ddlItemBillLevel.SelectedValue == "0" && hidTITID.Value!=string.Empty)
                {
                    int delresult = DU.executesql("delete from ivr_tran_item where TITID=" + hidTITID.Value + "and TRNID=" + strTranId + "");
                }
                if (intResult > 0)
                {
                  
                    //strsql = "Select Ident_Current('IVR_TRAN_ITEM') as TITID";
                    //DataTable DTTranid = DU.getdata(strsql);
                    //if (DTTranid.Rows.Count > 0)
                    //{
                    //    InsertItemTranDetailsBillLevel(strTranId, DTTranid.Rows[0]["TITID"].ToString(),i);
                    //}

                    InsertItemTranDetailsBillLevel(strTranId, hidTITID.Value, i);
                    intResult = 0;
                }
            }
        }
    }
    protected void InsertItemTranDetailsBillLevel(string tranId, string tranItemId, int rowId)
    {
        if (tranId.ToString() != string.Empty && tranItemId.ToString() != string.Empty)
        {
            string strTransDate = string.Empty;
            if (txtdate.Text.ToString() != string.Empty)
            {
                string[] str = txtdate.Text.ToString().Split('/');
                strTransDate = str[1].ToString() + "/" + str[0].ToString() + "/" + str[2].ToString();
            }
            DropDownList ddlItemBillLevel = (DropDownList)tblitem.Rows[rowId].FindControl("ddlitems" + rowId.ToString());
            TextBox txtQuantityBillLevel = (TextBox)tblitem.Rows[rowId].FindControl("txtquantity" + rowId.ToString());
            TextBox txtRateBillLevel = (TextBox)tblitem.Rows[rowId].FindControl("txtrate" + rowId.ToString());
            HiddenField hidLocationBillLevel = (HiddenField)tblitem.Rows[rowId].FindControl("hidLocationBillLevel" + rowId.ToString());
            HiddenField hidTIDID = (HiddenField)tblitem.Rows[rowId].FindControl("hidTIDID" + rowId.ToString());

            List<string> lstTIDIDLocationId = new List<string>();
            if (hidTIDID.Value.ToString() != string.Empty)
            {
                if (hidTIDID.Value.ToString().Contains('/'))
                {
                    string[] strtemp = hidTIDID.Value.ToString().Split('/');
                    foreach (string strTIDID in strtemp)
                    {
                        lstTIDIDLocationId.Add(strTIDID);
                    }
                }
                else
                {
                    lstTIDIDLocationId.Add(hidTIDID.Value);
                }
            }
            if (txtQuantityBillLevel.Text != string.Empty && txtRateBillLevel.Text != string.Empty)
            {
                if (hidLocationBillLevel.Value.ToString() != string.Empty && tranItemId != string.Empty) // tranItemId=TITID
                {
                    if (isBatchEnabled(ddlItemBillLevel.SelectedValue) && isWarrantyEnabled(ddlItemBillLevel.SelectedValue))
                    {
                        List<string> lstLocationId = new List<string>();
                        List<string> lstBatchId = new List<string>();
                        List<string> lstLocationQty = new List<string>();
                        List<string> lstWarranty1 = new List<string>();
                        List<string> lstWarrantyDetails1 = new List<string>();
                        if (hidLocationBillLevel.Value.ToString().Contains("/") && hidLocationBillLevel.Value.ToString().Contains("|") && hidLocationBillLevel.Value.ToString().Contains(":"))
                        {
                            string[] strMainArray = hidLocationBillLevel.Value.ToString().Split('/');
                            foreach (string strSubArray in strMainArray)
                            {
                                string[] str = strSubArray.ToString().Split(',');
                                lstLocationId.Add(str[0].ToString());
                                string[] str1 = str[1].ToString().Split('|');
                                lstLocationQty.Add(str1[0].ToString());
                                string[] str2 = str1[1].ToString().Split(':');
                                lstBatchId.Add(str2[0].ToString());
                                string[] str3 = str2[1].ToString().Split(';');
                                lstWarranty1.Add(str3[0].ToString());
                                lstWarrantyDetails1.Add(str3[1].ToString());
                            }
                        }
                        else
                        {
                            string[] str = hidLocationBillLevel.Value.ToString().Split(',');
                            lstLocationId.Add(str[0].ToString());
                            string[] str1 = str[1].ToString().Split('|');
                            lstLocationQty.Add(str1[0].ToString());
                            string[] str2 = str1[1].ToString().Split(':');
                            lstBatchId.Add(str2[0].ToString());
                            string[] str3 = str2[1].ToString().Split(';');
                            lstWarranty1.Add(str3[0].ToString());
                            lstWarrantyDetails1.Add(str3[1].ToString());
                        }
                        if (lstLocationId != null)
                        {
                            int Count = Convert.ToInt32(lstLocationId.Count);
                            for (int j = 0; j < Count; j++)
                            {
                                //Response.Write("location " + j.ToString());
                                if (j <= lstTIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@TIDID",lstTIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@TITID",tranItemId),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY",lstWarranty1[j].ToString()),
                                                               new SqlParameter("@WARRANTYPERIOD",lstWarrantyDetails1[j].ToString())                                                               
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_UpdateTransactionItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        //strsql = "Select Ident_Current('IVR_TRAN_ITEMDET') as TIDID";
                                        //DataTable DTTranTidid = DU.getdata(strsql);
                                        //if (DTTranTidid.Rows.Count > 0)
                                        //{
                                        SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","5"),
                                                               new SqlParameter("@ENTRYID",tranId),
                                                               new SqlParameter("@ITMROWID",lstTIDIDLocationId[j].ToString()), 
                                                               new SqlParameter("@ITMID",ddlItemBillLevel.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",lstLocationQty[j].ToString()),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtRateBillLevel.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strTransDate)
                                                                };
                                        int Result = DU.executeprocedure("USP_IVR_UpdateStockDetails", sparam1);
                                        if (Result > 0)
                                        {
                                            intResult = 0;
                                        }
                                        // }
                                    }
                                }
                                else if (j > lstTIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@TITID",tranItemId),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY",lstWarranty1[j].ToString()),
                                                               new SqlParameter("@WARRANTYPERIOD",lstWarrantyDetails1[j].ToString())                                                               
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_SaveTransactionItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        strsql = "Select Ident_Current('IVR_TRAN_ITEMDET') as TIDID";
                                        DataTable DTTranTidid = DU.getdata(strsql);
                                        if (DTTranTidid.Rows.Count > 0)
                                        {
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","5"),
                                                               new SqlParameter("@ENTRYID",tranId),
                                                               new SqlParameter("@ITMROWID",DTTranTidid.Rows[0]["TIDID"].ToString()), 
                                                               new SqlParameter("@ITMID",ddlItemBillLevel.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",lstLocationQty[j].ToString()),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtRateBillLevel.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strTransDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_SaveStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                        }
                                    }
                                }
                            }
                            if (lstTIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstTIDIDLocationId.Count; i++)
                                {
                                    int delresult = DU.executesql("delete from ivr_stockdet where entryid=" + tranId + " and itmrowid=" + lstTIDIDLocationId[i].ToString() + "");
                                }
                            }
                            if (lstTIDIDLocationId.Count > 0)
                            {
                                for (int i = 0; i < lstTIDIDLocationId.Count; i++)
                                {
                                    int resdelete = DU.executesql("delete from ivr_tran_itemdet where tidid=" + lstTIDIDLocationId[i].ToString() + "");
                                }
                            }
                        }
                    }
                    else if (isBatchEnabled(ddlItemBillLevel.SelectedValue) && !isWarrantyEnabled(ddlItemBillLevel.SelectedValue))
                    {
                        List<string> lstLocationId = new List<string>();
                        List<string> lstBatchId = new List<string>();
                        List<string> lstLocationQty = new List<string>();
                        if (hidLocationBillLevel.Value.ToString().Contains("/") && hidLocationBillLevel.Value.ToString().Contains("|"))
                        {
                            string[] strMainArray = hidLocationBillLevel.Value.ToString().Split('/');
                            foreach (string strSubArray in strMainArray)
                            {
                                string[] str = strSubArray.ToString().Split(',');
                                lstLocationId.Add(str[0].ToString());
                                string[] str1 = str[1].ToString().Split('|');
                                lstLocationQty.Add(str1[0].ToString());
                                lstBatchId.Add(str1[1].ToString());
                            }
                        }
                        else
                        {
                            string[] str = hidLocationBillLevel.Value.ToString().Split(',');
                            lstLocationId.Add(str[0].ToString());
                            string[] str1 = str[1].ToString().Split('|');
                            lstLocationQty.Add(str1[0].ToString());
                            lstBatchId.Add(str1[1].ToString());
                        }
                        if (lstLocationId != null)
                        {
                            int Count = Convert.ToInt32(lstLocationId.Count);
                            for (int j = 0; j < Count; j++)
                            {
                                if (j <= lstTIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                                   new SqlParameter("@TIDID",lstTIDIDLocationId[j].ToString()),
                                                                   new SqlParameter("@TITID",tranItemId),
                                                                   new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                                   new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                                   new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                                   new SqlParameter("@WARRANTY","0"),
                                                                   new SqlParameter("@WARRANTYPERIOD","0")                                                               
                                                               };
                                    int intResult = DU.executeprocedure("USP_IVR_UpdateTransactionItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        //strsql = "Select Ident_Current('IVR_TRAN_ITEMDET') as TIDID";
                                        // DataTable DTTranTidid = DU.getdata(strsql);
                                        //if (DTTranTidid.Rows.Count > 0)
                                        // {
                                        SqlParameter[] sparam3 ={
                                                                       new SqlParameter("@TYOFENTRY","5"),
                                                                       new SqlParameter("@ENTRYID",tranId),
                                                                       new SqlParameter("@ITMROWID",lstTIDIDLocationId[j].ToString()),
                                                                       new SqlParameter("@ITMID",ddlItemBillLevel.SelectedValue),
                                                                       new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                                       new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                                       new SqlParameter("@QTYPRIM",lstLocationQty[j].ToString()),                                                              
                                                                       new SqlParameter("@RATE_PRIMUNIT",txtRateBillLevel.Text.Trim()),                                                             
                                                                       new SqlParameter("@ENTRYDATE",strTransDate)
                                                                    };
                                        int Result = DU.executeprocedure("USP_IVR_UpdateStockDetails", sparam3);
                                        if (Result > 0)
                                        {
                                            Result = 0;
                                        }
                                        //}
                                    }
                                }
                                else if (j > lstTIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                                   new SqlParameter("@TITID",tranItemId),
                                                                   new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                                   new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                                   new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                                   new SqlParameter("@WARRANTY","0"),
                                                                   new SqlParameter("@WARRANTYPERIOD","0")                                                               
                                                               };
                                    int intResult = DU.executeprocedure("USP_IVR_SaveTransactionItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        strsql = "Select Ident_Current('IVR_TRAN_ITEMDET') as TIDID";
                                        DataTable DTTranTidid = DU.getdata(strsql);
                                        if (DTTranTidid.Rows.Count > 0)
                                        {
                                            SqlParameter[] sparam3 ={
                                                                       new SqlParameter("@TYOFENTRY","5"),
                                                                       new SqlParameter("@ENTRYID",tranId),
                                                                       new SqlParameter("@ITMROWID",DTTranTidid.Rows[0]["TIDID"].ToString()),
                                                                       new SqlParameter("@ITMID",ddlItemBillLevel.SelectedValue),
                                                                       new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                                       new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                                       new SqlParameter("@QTYPRIM",lstLocationQty[j].ToString()),                                                              
                                                                       new SqlParameter("@RATE_PRIMUNIT",txtRateBillLevel.Text.Trim()),                                                             
                                                                       new SqlParameter("@ENTRYDATE",strTransDate)
                                                                    };
                                            int Result = DU.executeprocedure("USP_IVR_SaveStockDetails", sparam3);
                                            if (Result > 0)
                                            {
                                                Result = 0;
                                            }
                                        }
                                    }
                                }
                            }
                            if (lstTIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstTIDIDLocationId.Count; i++)
                                {
                                    int delresult = DU.executesql("delete from ivr_stockdet where entryid=" + tranId + " and itmrowid=" + lstTIDIDLocationId[i].ToString() + "");
                                }
                            }
                            if (lstTIDIDLocationId.Count > 0)
                            {
                                for (int i = 0; i < lstTIDIDLocationId.Count; i++)
                                {
                                    int resdelete = DU.executesql("delete from ivr_tran_itemdet where tidid=" + lstTIDIDLocationId[i].ToString() + "");
                                }
                            }
                        }
                    }

                    else if (!isBatchEnabled(ddlItemBillLevel.SelectedValue) && !isWarrantyEnabled(ddlItemBillLevel.SelectedValue))
                    {
                        List<string> lstLocationId = new List<string>();
                        List<string> lstLocationQty = new List<string>();
                        if (hidLocationBillLevel.Value.ToString().Contains("/"))
                        {
                            string[] strMainArray = hidLocationBillLevel.Value.ToString().Split('/');
                            foreach (string strSubArray in strMainArray)
                            {
                                string[] str = strSubArray.ToString().Split(',');
                                lstLocationId.Add(str[0].ToString());
                                lstLocationQty.Add(str[1].ToString());
                            }
                        }
                        else
                        {
                            string[] str = hidLocationBillLevel.Value.ToString().Split(',');
                            lstLocationId.Add(str[0].ToString());
                            lstLocationQty.Add(str[1].ToString());
                        }
                        if (lstLocationId != null)
                        {
                            int Count = Convert.ToInt32(lstLocationId.Count);
                            for (int j = 0; j < Count; j++)
                            {
                                if (j <= lstTIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@TIDID",lstTIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@TITID",tranItemId),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),                                                               
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                               
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_UpdateTransactionItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        //strsql = "Select Ident_Current('IVR_TRAN_ITEMDET') as TIDID";
                                        //DataTable DTTranTidid = DU.getdata(strsql);
                                        //if (DTTranTidid.Rows.Count > 0)
                                        //{
                                        SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","5"),
                                                               new SqlParameter("@ENTRYID",tranId),
                                                               new SqlParameter("@ITMROWID",lstTIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@ITMID",ddlItemBillLevel.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID","0"),                                                               
                                                               new SqlParameter("@QTYPRIM",lstLocationQty[j].ToString()),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtRateBillLevel.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strTransDate)
                                                                };
                                        int Result = DU.executeprocedure("USP_IVR_UpdateStockDetails", sparam1);
                                        if (Result > 0)
                                        {
                                            intResult = 0;
                                        }
                                    }
                                }
                                else if (j > lstTIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@TIDID",lstTIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@TITID",tranItemId),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),                                                               
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                               
                                              };
                                    int intResult = DU.executeprocedure("USP_IVR_SaveTransactionItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        strsql = "Select Ident_Current('IVR_TRAN_ITEMDET') as TIDID";
                                        DataTable DTTranTidid = DU.getdata(strsql);
                                        if (DTTranTidid.Rows.Count > 0)
                                        {
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","5"),
                                                               new SqlParameter("@ENTRYID",tranId),
                                                               new SqlParameter("@ITMROWID",DTTranTidid.Rows[0]["TIDID"].ToString()),
                                                               new SqlParameter("@ITMID",ddlItemBillLevel.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID","0"),                                                               
                                                               new SqlParameter("@QTYPRIM",lstLocationQty[j].ToString()),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtRateBillLevel.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strTransDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_SaveStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                        }
                                    }
                                }
                            }
                            if (lstTIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstTIDIDLocationId.Count; i++)
                                {
                                    int delresult = DU.executesql("delete from ivr_stockdet where entryid=" + tranId + " and itmrowid=" + lstTIDIDLocationId[i].ToString() + "");
                                }
                            }
                            if (lstTIDIDLocationId.Count > 0)
                            {
                                for (int i = 0; i < lstTIDIDLocationId.Count; i++)
                                {
                                    int resdelete = DU.executesql("delete from ivr_tran_itemdet where tidid=" + lstTIDIDLocationId[i].ToString() + "");
                                }
                            }
                        }
                    }
                }
            }
            //else
            //{
            //    if (lstTIDIDLocationId.Count > 0 )
            //    {
            //        for (int i = 0; i < lstTIDIDLocationId.Count; i++)
            //        {
            //            int resdelete = DU.executesql("delete from ivr_tran_itemdet where tidid=" + lstTIDIDLocationId[i].ToString() + "");
            //        }
            //    }
            //}
        }
    }
    protected bool isBatchEnabled(string ItemId)//A common function for check item batch enabled or not
    {
        bool Flag = true;
        if (ItemId.ToString() != string.Empty)
        {
            strsql = "Select ITMBATCH from IVR_ITEM Where ITMID='" + ItemId.ToString() + "'";
            DataTable DT = DU.getdata(strsql);
            if (DT.Rows.Count > 0)
            {
                if (Convert.ToDouble(DT.Rows[0]["ITMBATCH"]) > 0)
                {
                    Flag = true;
                }
                else
                {
                    Flag = false;
                }
            }
        }
        return Flag;
    }
    protected bool isWarrantyEnabled(string ItemId)//A common function for check item warranty enabled or not
    {
        bool Flag = true;
        if (ItemId.ToString() != string.Empty)
        {
            strsql = "Select ITMBATCH, ITMBATCHOPT from IVR_ITEM Where ITMID='" + ItemId.ToString() + "'";
            DataTable DT = DU.getdata(strsql);
            if (DT.Rows.Count > 0)
            {
                if (Convert.ToDouble(DT.Rows[0]["ITMBATCH"]) > 0 && Convert.ToDouble(DT.Rows[0]["ITMBATCHOPT"]) == 1)
                {
                    Flag = true;
                }
                else
                {
                    Flag = false;
                }
            }
        }
        return Flag;
    }
    protected void InsertTranOthers(string tranId)
    {
        if (tranId.ToString() != string.Empty)
        {
            SqlParameter[] sparam =
                                    {
                                        new SqlParameter("@TRNID",tranId.ToString()),
                                        new SqlParameter("@PREPAREDBY",txtpreparedby.Text.Trim()),
                                        new SqlParameter("@CHECKEDBY",txtcheckedby.Text.Trim()),
                                        new SqlParameter("@AUTHRSDSIGNAT",txtauthorisedsignature.Text.Trim()),
                                        new SqlParameter("@NOTE",txtnote.Text.ToString()),
                                        new SqlParameter("@REMARKS",txtremarks.Text.Trim())                                        
                                    };
            DU.executeprocedure("USP_IVR_SaveTranOthers", sparam);
        }
    }
    protected void InsertTranDelivery(string tranId)
    {
        if (tranId.ToString() != string.Empty)
        {
            string strDeliveryDate = "1/1/1900";
            if (txtdeliverydate.Text != string.Empty)
            {
                string[] str = txtdeliverydate.Text.ToString().Split('/');
                strDeliveryDate = str[1] + "/" + str[0] + "/" + str[2];
            }
            SqlParameter[] sparam =
                                    {
                                        new SqlParameter("@TRNID",tranId.ToString()),
                                        new SqlParameter("@MODEOFDELIVERY",txtmodeofdelivery.Text.Trim()),
                                        new SqlParameter("@DELIVERYDATE",strDeliveryDate) ,
                                        new SqlParameter("@DOCUMENTNUM",txtdocumentno.Text.Trim()),
                                        new SqlParameter("@VEHICLENUM",txtvehicleno.Text.Trim()),
                                        new SqlParameter("@FREIGHTINDICATOR",txtfreightindicator.Text.Trim()),
                                        new SqlParameter("@TRANSPORTNAME",txttransportername.Text.Trim())                                                                              
                                    };
            int re = DU.executeprocedure("USP_IVR_SaveTranDelivery", sparam);
          
        }
    }
    //protected void Bind_VoucherNo()
    //{
    //    string MainVoucher = "";
    //    string Prepix = "";
    //    string Suffix = "";
    //    SqlParameter[] sparam =
    //                             {
    //                                 new SqlParameter("@BillFormatId",ddlFormat.SelectedValue)
    //                             };
    //    DataTable DTNum = DU.getdatausingprocedure("USP_GetPOVoucherNoFormat", sparam);
    //    if (DTNum.Rows.Count > 0 && DTNum.Rows[0][0].ToString() != string.Empty)
    //    {
    //        strsql = "Select * from IVR_TRANFORMATNUM where TFOID='" + ddlFormat.SelectedValue + "'";
    //        DataTable DT = DU.getdata(strsql);
    //        if (DT.Rows.Count > 0)
    //        {
    //            if (DT.Rows[0]["NUMBERINGMETHOD"].ToString() == "True")
    //            {
    //                string SetZero = "";
    //                int NumLength = Convert.ToInt32(DT.Rows[0]["NUMSTART"].ToString().Length);
    //                int NumWidth = Convert.ToInt32(DT.Rows[0]["NUMDIGITS"].ToString());
    //                int Diff = NumWidth - NumLength;
    //                if (NumLength < NumWidth)
    //                {
    //                    for (int i = 0; i < Diff; i++)
    //                    {
    //                        SetZero += "0";
    //                    }

    //                }
    //                double Povoucher = Convert.ToDouble(DTNum.Rows[0]["PoVoucherNo"].ToString());
    //                MainVoucher = SetZero + (Povoucher + 1).ToString();
    //                txtVoucher.Attributes.Add("onKeyPress", "return false");
    //                txtVoucher.Attributes.Add("onKeyDown", "return false");
    //            }
    //            else
    //            {
    //                txtVoucher.Attributes.Add("onKeyPress", "return true");
    //                txtVoucher.Attributes.Add("onKeyDown", "return true");
    //            }
    //            Prepix = DT.Rows[0]["NUMPREFIX"].ToString();
    //            Suffix = DT.Rows[0]["NUMSUFFIX"].ToString();

    //        }
    //    }
    //    else
    //    {
    //        strsql = "Select * from IVR_TRANFORMATNUM where TFOID='" + ddlFormat.SelectedValue + "'";
    //        DataTable DT = DU.getdata(strsql);
    //        if (DT.Rows.Count > 0)
    //        {
    //            if (DT.Rows[0]["NUMBERINGMETHOD"].ToString() == "True")
    //            {
    //                string SetZero = "";
    //                int NumLength = Convert.ToInt32(DT.Rows[0]["NUMSTART"].ToString().Length);
    //                int NumWidth = Convert.ToInt32(DT.Rows[0]["NUMDIGITS"].ToString());
    //                int Diff = NumWidth - NumLength;
    //                if (NumLength < NumWidth)
    //                {
    //                    for (int i = 0; i < Diff; i++)
    //                    {
    //                        SetZero += "0";
    //                    }

    //                }
    //                MainVoucher = SetZero + DT.Rows[0]["NUMSTART"].ToString();
    //                txtVoucher.Attributes.Add("onKeyPress", "return false");
    //                txtVoucher.Attributes.Add("onKeyDown", "return false");
    //            }
    //            else
    //            {
    //                txtVoucher.Attributes.Add("onKeyPress", "return true");
    //                txtVoucher.Attributes.Add("onKeyDown", "return true");
    //            }
    //            Prepix = DT.Rows[0]["NUMPREFIX"].ToString();
    //            Suffix = DT.Rows[0]["NUMSUFFIX"].ToString();
    //        }
    //    }
    //    txtPrefix.Text = Prepix.ToString();
    //    txtVoucher.Text = MainVoucher.ToString();
    //    txtSuffix.Text = Suffix.ToString();
    //}
    //protected void grdview_RowDataBound(object sender, GridViewRowEventArgs e)
    //{
    //    if (e.Row.RowType == DataControlRowType.DataRow)
    //    {
    //        string  formateid = grdview.DataKeys[e.Row.RowIndex].Values[0].ToString();
    //        string supplierid = grdview.DataKeys[e.Row.RowIndex].Values[1].ToString();
    //        string trnid = grdview.DataKeys[e.Row.RowIndex].Values[2].ToString();
    //        string finyear = grdview.DataKeys[e.Row.RowIndex].Values[3].ToString();

    //        DataTable dt_formate = DU.getdatausingprocedure("usp_ivr_get_tranformatename");
    //        if (dt_formate.Rows.Count > 0)
    //        {
    //            DataView dv = dt_formate.DefaultView;
    //            dv.RowFilter = "TFOID = " + formateid + "";
    //            dt_formate = dv.ToTable();
    //            ((Label)e.Row.FindControl("lbldcfomate")).Text = dt_formate.Rows[0]["formatname"].ToString();
    //        }
            
    //        DataTable dt_supplier = DU.getdatausingprocedure("USP_ACC_GetLedgerForPurchaseInvoice");
    //        if (dt_supplier.Rows.Count > 0)
    //        {
    //            DataView dv = dt_supplier.DefaultView;
    //            dv.RowFilter = "LID=" + supplierid + "";
    //            dt_supplier = dv.ToTable();
    //            ((Label)e.Row.FindControl("lblsupplier")).Text = dt_supplier.Rows[0]["LName"].ToString();
    //        }
    //        string taxgroup = ((Label)e.Row.FindControl("lbltaxgroup")).Text.ToString();
    //        if (taxgroup.ToString() != string.Empty)
    //        {
    //            SqlParameter[] parma = { 
    //                            new SqlParameter("@ISDCIN","1")
    //                           };
    //            DataTable dt_taxgroup = DU.getdatausingprocedure("USP_IVR_GetDCGroup", parma);
    //            if (dt_taxgroup.Rows.Count > 0)
    //            {
    //                DataView dv = dt_taxgroup.DefaultView;
    //                dv.RowFilter = "ID=" + taxgroup.ToString() + "";
    //                dt_taxgroup = dv.ToTable();
    //                ((Label)e.Row.FindControl("lbltaxgroup")).Text = dt_taxgroup.Rows[0]["SubClass"].ToString();
    //            }
    //        }
           
    //        ((HyperLink)e.Row.FindControl("hypdetails")).Attributes.Add("onclick", "Open_DCInward_Details('"+formateid+"','"+supplierid+"','"+trnid+"','"+finyear+"')");
    //        //((HyperLink)e.Row.Cells[9].Controls[1]).Attributes.Add("onclick", "open_Purchase_Recive_Details('" + poid + "','" + transferedid + "','" + supplier + "','" + taxgroup + "','" + trnid + "')");
    //    }
    //}

  
}
